<?php
	
	require_once("fta.201003310000/fta.php");
	fta_registerModules(
		array(
		"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
		"site/fta/config",
		"site/components/MAIArtworks",
		"FTAFormMailer/ftaFormMailer",
		"FTAWebPage/ftaDefaultWidgets"
	));	
	
	$urlfragment = extractStringWithKeyFromArray("urlfragment", $_REQUEST, null);
	//Need to default it to top one if not set or another page.
	if(is_null($urlfragment)){
		header('location: /Artworks-For-Sale/');
	} else {
		$urlfragment = urlFragmentCleanRestore($urlfragment);
	}
	
	//echo "Url fragment = '" . $urlfragment . "' ";
	
	// /*
	//need to redirect if no type found
	$o = mai_getSharedArtworksObject();
	$artwork = $o->getArtworkByUrlFragment($urlfragment);
	if($artwork == false){
		header('location: /Artworks-For-Sale/');
	}
	// */
	
	//echo "Artwork = <pre>";print_r($o->artwork);echo "</pre>";
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Enquire about this artwork</title>

<?php include ("../includes/external-files.php"); ?>

<link rel="stylesheet" type="text/css" href="/css/popups.css">


<script src="/js/jquery.inlined-forms.js" type="text/javascript"></script>    


<?php include ("../includes/analytics.php"); ?>   
</head>

<body>
<h1>Artwork enquiry</h1>

<div id="container-popups">

    <h2><?php echo $o->artwork->title; ?></h2>
    
        

        
		
		
		
		
		
		<?php


					$authInfo = setupPublicUser();
					
					//ie cluster fuck 
					$submit_x = extractBooleanWithKeyFromArray('enquiry-submit_x',$_POST,false);
					$submit_y = extractBooleanWithKeyFromArray('enquiry-submit_y',$_POST,false);
					$submit = ($submit_x || $submit_y);
					$submit = extractBooleanWithKeyFromArray('enquiry-submit',$_POST,$submit);
					
					
					$formDescriptor = fta_getFormMailerFormDescriptor(2172,$db);
				
					$formSent = false;
					if ( $submit ) {
						$invalidFields = array();
						$recipients = array();		
						$formSent = fta_formMailerSendForm($formDescriptor,$_POST,$recipients, $authInfo, $invalidFields, $db );
						
				
						$toAddress = extractEmailWithKeyFromArray('email',$_REQUEST ,null);
						if ($formSent && !is_null($toAddress) && $formDescriptor->sendThankYouEmail){
				
							fta_formMailerSendThankYouEmail(
								array(
								$toAddress	
								),$formDescriptor
							);
						}		
					}
					
					if (!$formSent){
						
						
				
		?>	
		<div class="content-block">
        	Interested in this piece of art?  <br><br>
			Let us know Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus venenatis. Nullam sodales suscipit mi. Sed massa.       
		</div>
		
        
        <form id="enquiry-form" method="POST" action="<?= $_SERVER['REQUEST_URI'] ?>">
                    
                    
                    <div>
                    
                    <input type="hidden" name="artwork" value="<?php echo $o->artwork->title; ?>" />
                    
                    <label for="name" class="inlined">Name:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('name',$_REQUEST, $formDescriptor); ?> type="text"  /><?= fta_getFormMailerValidationMessageForField('name', $invalidFields, $formDescriptor); ?>
					</div>
                    
                    <div>
                    <label for="email" class="inlined">Email:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('email',$_REQUEST, $formDescriptor); ?> type="text"  /><?= fta_getFormMailerValidationMessageForField('email', $invalidFields, $formDescriptor); ?>
					</div>

					
                    <div>
                    <label for="phone" class="inlined">Phone:</label>
                    <input class="input-text" <?= fta_getFormMailerInputIdAndValue('phone',$_REQUEST, $formDescriptor); ?> type="text"  /><?= fta_getFormMailerValidationMessageForField('phone', $invalidFields, $formDescriptor); ?>
					</div>
					
                    <div>
                    <label for="message" class="inlined">Your enquiry:</label>
                    <textarea class="input-text" name="message" rows="8" ><?= fta_getFormMailerTextAreaValue('message',$_REQUEST, $formDescription); ?></textarea>
					</div>
                    
                    <input id="enquiry-submit" name="enquiry-submit" type="submit" value='1' />
                    <?php //<input src="/images/submit.gif" name="contactSubmit" type="image" class="contactSubmit" value='1'/> ?>
        </form>
        
        
				<?php 
					} else {
				?>	
				<div class='artworkEnquiryThankyou'>	
					Thanks!  Your enquiry has been sent, and we'll be in touch shortly.
				</div>
					
						
				<?php		
					}
				?>
        
</div>

</body>
</html>
